﻿using System;
using System.Collections.Generic;
using System.Data.OleDb;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace TemplateEmailSender
{
    static class Entry
    {
        public static List<List<string>> items = new List<List<string>>();
        static public bool GetEntries(string fileName)
        {
            string conStr = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + fileName +
                ";Extended Properties='Excel 12.0 Xml;HDR=YES';";
            OleDbConnection entryFile = new OleDbConnection(conStr);
            using (entryFile)
            {
                try
                {
                    entryFile.Open();
                    for (int i = 0; i < Template.menu.Count; i++)
                    {
                        List<string> temp = new List<string>();
                        OleDbCommand getEntries = new OleDbCommand("SELECT " + Template.menu[i] + " FROM [entries$]", entryFile);
                        OleDbDataReader result;
                        result = getEntries.ExecuteReader();
                        while (result.Read())
                        {
                            temp.Add(result.GetString(0));
                        }
                        items.Add(temp);
                    }
                    return true;
                }
                catch (Exception)
                {

                    MessageBox.Show("The excel sheet in the file must be named: entries !!!");
                    return false;
                }


            }
        }
    }
}
